package com.wg.elasticsearch.result;

public class ResultSupport<T> {

    /**
     * 备注
     */
    private String remark;

    /**
     * 返回编号
     */
    private Integer resultCode;

    /**
     * 是否成功
     */
    private boolean success = false;

    /**
     * 总条数
     */
    private Integer totalCount;

    /**
     * 装载对象
     */
    private T module;
    /**
     * 异常
     */
    private Exception exception;

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Integer getResultCode() {
        return resultCode;
    }

    public void setResultCode(Integer resultCode) {
        this.resultCode = resultCode;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public T getModule() {
        return module;
    }

    public void setModule(T module) {
        this.module = module;
    }

    public Exception getException() {
        return exception;
    }

    public void setException(Exception exception) {
        this.exception = exception;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    /**
     * 成功
     * @param module
     * @param <T>
     * @return
     */
    public static <T> ResultSupport<T> success(T module) {
        ResultSupport<T> result = new ResultSupport<T>();
        result.setSuccess(true);
        result.setModule(module);
        return result;
    }

    /**
     * 成功
     * @param module
     * @param <T>
     * @return
     */
    public static <T> ResultSupport<T> successPage(T module , Long totalCount) {
        ResultSupport<T> result = new ResultSupport<T>();
        result.setSuccess(true);
        result.setTotalCount(totalCount.intValue());
        result.setModule(module);
        return result;
    }

    /**
     * 成功并返回code
     * @param module
     * @param <T>
     * @return
     */
    public static <T> ResultSupport<T> success(int resultCode,T module , String remark) {
        ResultSupport<T> result = new ResultSupport<T>();
        result.setSuccess(true);
        result.setResultCode(resultCode);
        result.setModule(module);
        result.setRemark(remark);
        return result;
    }

    /**
     * 成功
     * @param module
     * @param <T>
     * @return
     */
    public static <T> ResultSupport<T> success(T module , String remark) {
        ResultSupport<T> result = new ResultSupport<T>();
        result.setSuccess(true);
        result.setModule(module);
        result.setRemark(remark);
        return result;
    }

    /**
     * 成功
     * @param <T>
     * @return
     */
    public static <T> ResultSupport<T> success() {
        ResultSupport<T> result = new ResultSupport<T>();
        result.setSuccess(true);
        return result;
    }

    /**
     * 失败
     * @param errCode
     * @param msg
     * @param <T>
     * @return
     */
    public static <T> ResultSupport<T> failure(String errCode, String msg) {
        ResultSupport<T> result = new ResultSupport<T>();
        result.setSuccess(false);
        result.setRemark(msg);
        return result;
    }

    /**
     * 失败
     * @param errCode
     * @param msg
     * @param <T>
     * @return
     */
    public static <T> ResultSupport<T> failure(Integer errCode, String msg) {
        ResultSupport<T> result = new ResultSupport<T>();
        result.setSuccess(false);
        result.setResultCode(errCode);
        result.setRemark(msg);
        return result;
    }

    /**
     * 失败
     * @param errCode
     * @param msg
     * @param <T>
     * @return
     */
    public static <T> ResultSupport<T> failure(Integer errCode, String msg , T module) {
        ResultSupport<T> result = new ResultSupport<T>();
        result.setSuccess(false);
        result.setResultCode(errCode);
        result.setRemark(msg);
        result.setModule(module);
        return result;
    }

    /**
     * 失败
     * @param msg
     * @param <T>
     * @return
     */
    public static <T> ResultSupport<T> failure( String msg) {
        ResultSupport<T> result = new ResultSupport<T>();
        result.setSuccess(false);
        result.setRemark(msg);
        return result;
    }

}

